import moment from 'moment';
moment.locale("zh-cn");
export default class comment {
  constructor({
    id,
    nickname,
    userid,
    content,
    liked,
    likedCount,
    time,
    avator,
    vipright,
    vipType
  }) {
    this.id = id;
    this.nickname = nickname;
    this.userid = userid;
    this.content = content;
    this.liked = liked;
    this.likedCount = likedCount;
    this.time = time;
    this.avator = avator;
    this.vipright = vipright;
    this.vipright = vipType;
  }
}


export function createCommnent(data) {
  return new comment({
    id: data.commentId,
    nickname: data.user.nickname,
    userid: data.user.userId,
    content: data.content && formartConent(data.content),
    liked: data.liked,
    likedCount: data.likedCount,
    time: formatTime(data.time),
    avator: data.user.avatarUrl,
    vipright: data.user.vipRights,
    vipType: data.user.vipType
  })
}
// 出现\n 换行的时候插入 <br/> 标签
export function formartConent(content) {
  if (content) {
    content = content.replace(/(\n)|(\r\n)/g, "<br />");
    return content;
  }

}

function formatTime(time) {
  return moment(time).format("MMMDo")
}
